import { _decorator, type Button, find, Label } from 'cc';
import { Ab_BasePopUp_bA } from '../../../A-FRAME/component/ui.pop-up';
import { Ab_ClientAPI_bA } from '../../api/client.api';
import Ab_GameDC_bA from '../../manager/data.game.center';
import Ab_GameAssets_bA from '../../manager/game.assets';
import type { Ab_Popup_bA } from '../page/popup';
const { ccclass, property } = _decorator;

@ccclass('Ab_LuckyBox_bA')
export class Ab_LuckyBox_bA extends Ab_BasePopUp_bA<typeof Ab_Popup_bA, boolean> {
	protected Ab_default_return_bA: boolean;

	protected Ab_initAfterOnLoad_bA(){
		this.Ab_renderLocalUI_bA();
	}

	public Ab_onShow_bA(){
		Ab_GameDC_bA.Ab_Trigger_bA.Ab_HILIT_DIAMOND_bA = true;
		Ab_BasePopUp_bA.Ab_jelly_enter_bA(this.node);
	}

	protected Ab__click_event__bA: { [name: string]: (this: Ab_LuckyBox_bA, button: Button) => void; } = {
		close(btn){
			btn.interactable = false;
			this.Ab_exit_bA(false).then(()=>btn.interactable = true);
		},
		async video(btn){
			btn.interactable = false;
			await Ab_ClientAPI_bA.Ab_AD_bA('incentive');
			await this.Ab_exit_bA(true);
			btn.interactable = true;
		}
	}

	private async Ab_exit_bA(reap: boolean){
		await Ab_BasePopUp_bA.Ab_jelly_leave_bA(this.node);
		this.Ab_close_bA(reap);
		Ab_GameDC_bA.Ab_Trigger_bA.Ab_HILIT_DIAMOND_bA = false;
	}

	private Ab_renderLocalUI_bA(){
		(<const>[
			['lbl-title', 19],
			['lbl-video', 21],
			['lbl-desc', 20, 3],
			['close', 22]
		]).forEach(([name, idx, ...args])=>this.node.getChildByName(name).getComponent(Label).string = Ab_GameAssets_bA.Ab_getLangText_bA(idx, ...args))

		find('diamond/value', this.node).getComponent(Label).string = 'X 3';
	}
}

